<?php

class activityModel extends Model{
    public function getAllAction(){
    	$strip = 5;
		$page = isset($_GET['page'])?$_GET['page']:0;
		$start = $page*$strip;
		$sql = "select a.*,u.username,t.type from activity a LEFT JOIN `user` u on a.uid = u.id LEFT JOIN activitytype t on a.activityType = t.id order by activityDate limit $start,$strip";
        $str = $this->link->selectDB($sql);
        echo json_encode($str);
    }
	public function getClassAction(){
    	$strip = 5;
		$page = isset($_GET['page'])?$_GET['page']:0;
		$tid = isset($_GET['type'])?$_GET['type']:0;
		$start = $page*$strip;
		$sql = "select a.*,u.username,t.type from activity a LEFT JOIN `user` u on a.uid = u.id LEFT JOIN activitytype t on a.activityType = t.id WHERE t.id=$tid order by activityDate limit $start,$strip";
        $str = $this->link->selectDB($sql);
        echo json_encode($str);
    }
	public function getSearchAction(){
    	$strip = 5;
		$page = isset($_GET['page'])?$_GET['page']:0;
		$getsearch = isset($_GET['getsearch'])?$_GET['getsearch']:'';
		$start = $page*$strip;
		$sql = "select a.*,u.username,t.type from activity a LEFT JOIN `user` u on a.uid = u.id LEFT JOIN activitytype t on a.activityType = t.id WHERE a.activityName LIKE '%$getsearch%' order by activityDate limit $start,$strip";
        $str = $this->link->selectDB($sql);
        echo json_encode($str);
    }
	
	public function getGarbageAction(){
    	$strip = 5;
		$page = isset($_GET['page'])?$_GET['page']:0;
		$start = $page*$strip;
		$sql = "select a.*,u.username,t.type from activity a LEFT JOIN `user` u on a.uid = u.id LEFT JOIN activitytype t on a.activityType = t.id where a.status=2 order by activityDate limit $start,$strip";
        $str = $this->link->selectDB($sql);
        echo json_encode($str);
    }
	public function PagerAction(){
			$strip = 5;
			$sql = "select count(id) from activity";
			$data = $this->link->selectDB($sql);
			$row = ceil($data[0]['count(id)']/$strip);
			echo json_encode($row);
	}
public function getSearchPagerAction(){
			$strip = 5;
			$getsearch = isset($_GET['getsearch'])?$_GET['getsearch']:'';
			$sql = "select count(id) from activity a WHERE a.activityName LIKE '%$getsearch%'";
			$data = $this->link->selectDB($sql);
			$row = ceil($data[0]['count(id)']/$strip);
			echo json_encode($row);
	}
	public function getClassPagerAction(){
			$strip = 5;
			$tid = isset($_GET['type'])?$_GET['type']:0;
			$sql = "select count(a.id) from activity a LEFT JOIN activitytype t on a.activityType = t.id WHERE t.id=$tid";
			$data = $this->link->selectDB($sql);
			$row = ceil($data[0]['count(a.id)']/$strip);
			echo json_encode($row);
	}
public function GarbagePagerAction(){
			$strip = 5;
			$sql = "select count(id) from activity where status = 2";
			$data = $this->link->selectDB($sql);
			$row = ceil($data[0]['count(id)']/$strip);
			echo json_encode($row);
	}
	public function classAction(){
			$sql = "select * from activityType";
			$data = $this->link->selectDB($sql);
			echo json_encode($data);
	}
	
}